package com.cn.demo.service.impl;

import com.cn.demo.entity.Internship;
import com.cn.demo.entity.InternshipLog;
import com.cn.demo.mapper.InternshipMapper;
import com.cn.demo.service.InternshipService;
import com.cn.demo.service.PageInfoUtilServer;
import com.cn.demo.utils.Result;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

@Service
@Transactional
public class InternshipServiceImpl implements InternshipService {
    @Autowired
    private InternshipMapper internshipMapper;

    @Autowired
    private PageInfoUtilServer pageInfoUtilServer;

    @Override
    public Result getOrganizationStudentInternshipLog(Integer page, Integer limit, String internshipId) {
        PageHelper.startPage(page,limit);
        List<InternshipLog> internshipLogList =  internshipMapper.getOrganizationStudentInternshipLog(internshipId);
        return Result.success(pageInfoUtilServer.currency(internshipLogList));
    }

    @Override
    public Result getInternshipCorporation(String studentId, String curriculumInternshipId) {
        Internship internship = internshipMapper.getInternshipCorporation(studentId,curriculumInternshipId);
        return Result.success(internship);
    }

    @Override
    public Result addInternshipCorporation(Internship internship) {
        internship.setInternshipId(UUID.randomUUID().toString());
        if (internshipMapper.insert(internship)>0){
            return Result.success();
        }
        return Result.error();
    }
}